class Solution 
{
public:
    ListNode* reverseBetween(ListNode* head, int left, int right)
    {
        ListNode* fkNode = new ListNode(-1);
        fkNode->next = head;
        ListNode* pre = fkNode;
        for (int i = 0; i < left - 1; i++)
        {
            pre = pre->next;
        }
        ListNode* cur = pre->next;
        ListNode* next;
        for (int i = 0; i < right - left; i++)
        {
            next = cur->next;
            cur->next = next->next;
            next->next = pre->next;
            pre->next = next;
        }
        return fkNode->next;
    }
};